<template>
  <div class="info"> 
    <div id="divId"
         class="echart"></div>
  </div>
</template>

<script>
import { getCurrentInstance } from 'vue'
import { ElMessage } from 'element-plus'
 /* eslint-disable */ 
export default {
  name: 'App',
  data () {
    return {
      list: [],
      chart: null
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    init () {
      this.chart = echarts.init(document.getElementById('divId'))// eslint-disable-line

      this.chart.resize()
      this.chart.clear()
      this.chart.showLoading({
        text: '数据正在努力加载...',
        textStyle: { fontSize: 30, color: '#444' },
        effectOption: { backgroundColor: 'rgba(0, 0, 0, 0)' }
      })
      this.getData()
    },
    getData () {
     
      const appConfig = getCurrentInstance()?.appContext.config.globalProperties
      appConfig.$http
        .get('/api/N95API/record_list.aspx')
        .then(({ data: res }) => {
          if (res.status !== 200) {
            ElMessage.warning(res.msg)
          }
          this.list = res.items; 

          this.drawChart()
          this.hideLoading()
        }).catch(() => { })
    },
    drawChart () {
      let option = {
        tooltip: { 
          trigger: 'axis'
        },
        grid: {
          left: '5%',
          right: '15%',
          bottom: '10%'
        },
        xAxis: {
          data: this.list.map(function (item) {
            return item.record_time;
          }), 
          interval:10
        },
        yAxis: {},
        // dataZoom: [{
        //   startValue: this.list[this.list.length / 2].record_time
        // }],
        visualMap: {
          top: 50,
          right: 10,
          pieces: [{
            gt: 0,
            lte: 3,
            color: '#93CE07'
          }, {
            gt: 3,
            lte: 6,
            color: '#FBDB0F'
          }, {
            gt: 6,
            lte: 9,
            color: '#FC7D02'
          }, {
            gt: 9,
            lte: 12,
            color: '#FD0100'
          }, {
            gt: 12,
            lte: 15,
            color: '#AA069F'
          }, {
            gt: 15,
            color: '#AC3B2A'
          }],
          outOfRange: {
            color: '#999'
          }
        },

        series: {
          type: 'line',
          data: this.list.map(function (item) {
            return item.count;
          }),
            markPoint: {
                data: [
                    {type: 'max', name: '最大值'}
                ]
            },
         
        }
      }
      this.chart.setOption(option, true)
    },
    hideLoading () {
      this.chart.hideLoading()
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
.echart {
  height: 750px;
}
</style>
